package snapex.core.controller;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping
public class ViewController {

	@GetMapping(value = "/login", produces = MediaType.TEXT_HTML_VALUE)
	public String loginView() {
		log.debug("****login view*********");
		
		return "login";
	}

	@PostMapping(value = "/login/error", produces = MediaType.TEXT_HTML_VALUE)
	public String loginErrorView(ModelMap modelMap) {
		log.debug("****login error view*********");
			
//		Enumeration<String> names = request.getParameterNames();
//		
//		while(names.hasMoreElements()) {
//			String name = names.nextElement();
//			log.debug("*****name:{}, value={}", name, request.getParameter(name));
//		}
		
		modelMap.put("errorMessage", "Failed to verify your credentials");
		return "login";
	}

//	@PostMapping(value = "/login/error",produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
//	@ResponseBody
//	public ResponseEntity loginError(){		
//		return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
//	}
	
	@PostMapping(value = "/logout", produces = MediaType.TEXT_HTML_VALUE)
	public String logoutView(ModelMap modelMap) {
		log.debug("****logout view*********");
		
		modelMap.put("message", "You have been signed out");
		
		return "login";
	}
}